package cn.rui.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.rui.common.ResponseBean;
import cn.rui.pojo.vo.PageVo;
import cn.rui.pojo.vo.TestExamAnswerVo;
import cn.rui.service.exam.UserAnswerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author 徽州大都督
 * @date 2021/6/28
 */

@RestController
@RequestMapping("answer")
@Api(tags = "用户答题模块")
@Slf4j
public class UserAnswerController {

    @Autowired
    private UserAnswerService userAnswerService;

    @PostMapping("save")
    @ApiOperation(value = "提交考试答案")
    @SaCheckLogin
    public ResponseBean answerSave(@RequestBody TestExamAnswerVo testExamAnswerVo) {
        return userAnswerService.save (testExamAnswerVo);
    }


    @PostMapping("findPage/{paperId}")
    @ApiOperation(value = "根据试卷id查询考试学生信息")
    @SaCheckLogin
    public ResponseBean findPage(@RequestBody PageVo pageVo, @PathVariable("paperId") Long paperId, HttpSession session) {
        return userAnswerService.findPage (pageVo, paperId, session);
    }

    @GetMapping("findDetail/{paperId}/{userId}")
    @ApiOperation(value = "根据试卷id和学生id查询答题详细信息")
    @SaCheckLogin
    public ResponseBean findDetail(@PathVariable("paperId") Long paperId, @PathVariable("userId") Integer userId, HttpSession session) {
        return userAnswerService.findDetail (paperId, userId, session);
    }

    @PostMapping("reviewScore/{userId}/{paperId}/{score}/{questionId}")
    @ApiOperation(value = "老师评分")
    @SaCheckLogin
    public ResponseBean reviewScore(@PathVariable("paperId") Long paperId, @PathVariable("userId") Integer userId,@PathVariable("score")Integer score, @PathVariable("questionId")Long questionId,HttpSession session) {
        return userAnswerService.reviewScore (paperId, userId,score,questionId, session);
    }
}
